{extend name="default/base" /}
{block name="css"}
<link rel="stylesheet" type="text/css" href="__STATIC__/plugins/webuploader/webuploader.css?v={$v}" />
{/block}
{block name="main"}
<div class="wst-body">
    <table class="wst-form">
        <tr>
            <td colspan='2' >
                <div class='wst-tips-box' style='margin-top:10px;'>
                    <div class='icon'></div>
                    <div class='tips' >
                        1.请确保商品价格必须大于0，否则将自动默认为0.01。<br/>
                        2.请确保商品库存不能为负数，否则将自动默认为0。<br/>
                        3.请勿重复上传, 否则将造成重复商品数据。<br/>
                        4.请保证导入的数据在Excel的第一个工作表(Sheet)。<br/>
                        5.若Excel上某一行第一列为空则代表商品数据导入完毕。<br/>
                        6.若没有数据模板，请点击<a href='__STATIC__/template/goods.xls' style='color:blue;' target='_blank'>下载Excel模板</a>。<br/>
                        7.推荐使用谷歌浏览器或者火狐浏览器Firefox以获得更佳体验。<br/>
                    </div>
                    <div style="clear:both"></div>
                </div>
            </td>
        </tr>
        <tr>
            <th align='right' width='90'>商品数据：</th>
            <td>
                <div id="filePicker" style='margin-left:0px;'>导入商品数据</div>
            </td>
        </tr>
        <tr style="display: none;">
            <th align='top' style="color: red;font-weight: bold;vertical-align: text-top;" width='90'>错误信息：</th>
            <td id="errMsgBox"></td>
        </tr>
    </table>
</div>
{/block}
{block name="js"}
<script type='text/javascript' src='__STATIC__/plugins/webuploader/webuploader.js?v={$v}'></script>
<script>
    var uploading = null;
    $(function(){
        var uploader = WST.upload({
            server:"{:url('shop/imports/importGoods')}",pick:'#filePicker',
            formData: {dir:'temp'},
            callback:function(f,file){
                layer.close(uploading);
                uploader.removeFile(file);
                var json = WST.toJson(f);
                $('#errMsgBox').parent().hide();
                if(json.status==1){
                    uploader.refresh();
                    WST.msg('导入数据成功!已导入数据'+json.importNum+"条", {icon: 1});
                    if(json.specErrMsg && json.specErrMsg.length>0){
                        var _msg = json.specErrMsg.map(function(x){return "<div style='color: red;font-weight: bold;'>"+x.msg+"</div>"});
                        $('#errMsgBox').html(_msg.join('')).parent().show();
                    }
                }else{
                    WST.msg('导入数据失败,出错原因：'+json.msg, {icon: 5});
                }
            },
            progress:function(rate){
                uploading = WST.msg('正在导入数据，请稍后...');
            }
        });
    });
</script>
{/block}